package com.bishe.demo.controller;

import com.bishe.demo.pojo.Commodity;
import com.bishe.demo.pojo.Store;
import com.bishe.demo.pojo.vo.Status;
import com.bishe.demo.service.CommodityService;
import com.bishe.demo.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CommodityController {

    @Autowired
    CommodityService commodityService;

    @Autowired
    StoreService storeService;

    @RequestMapping("tiaozhuanAddCom")
    public String tiaozhuanAddCom(HttpSession httpSession){

        List<Store> storeList = storeService.selectStore();
        httpSession.setAttribute("storel",storeList);

        return "addCommodity";
    }
    //接收添加的商品信息

    @RequestMapping("receiveAddcom")
    public String receiveAddcom( String commodityName,
                                Integer commodityNumber, String commodityCategory,
                                Integer commodityCost, Integer commodityPrice,
                                HttpSession httpSession){
        Status status = commodityService.addCom(commodityName,commodityNumber,commodityCategory
        ,commodityCost,commodityPrice);
        httpSession.setAttribute("addcomMsg",status.getMsg());

        return "addCommodityMsg";
    }
    @RequestMapping("tiaozhuanDeleteCom")
    public String tiaozhuanDeleteCom(HttpSession httpSession){
        List<Commodity> list1 = commodityService.selectAllCom();
        httpSession.setAttribute("deleteList",list1);


        return "deleteCom";
    }
    //接收删除商品信息
    @RequestMapping("receiveDeleteCom")
    public String receiveDeleteCom(Integer comId,HttpSession httpSession){

        Status status = commodityService.deleteCom(comId);
        httpSession.setAttribute("deleteComMsg",status.getMsg());
        return "deleteComMsg";
    }

    @RequestMapping("tiaozhuanSelectCom")
    public String tiaozhuanSelectCom(HttpSession httpSession){
        List<Commodity> list1 = commodityService.selectAllCom();
        httpSession.setAttribute("deleteList",list1);
        return "selectCom";
    }
}
